<?php

namespace api\store;

use api\common\Api;

class StoreApi extends Api
{
    protected $store;
    protected $data_name = 'demo';

    public function __construct()
    {
        $this->store = new Store($this->data_name);
    }

    public function lists()
    {
        $page = input('page');//获得分页
        $rows = input('rows', 10);//获得分页
        $data = $this->store->select()->page($page, $rows);
        return $this->success($data);
    }

    public function add()
    {
        $item = input('');//获得所有传递过来的数据
        $data = $this->store->add($item);
        return $this->success($data);
    }

    public function edit()
    {
        $item = input('');//获得所有传递过来的数据
        $data = $this->store->edit($item);
        return $this->success($data);
    }

    public function get()
    {
        $id = input('id');//获得ID
        $data = $this->store->get($id);
        return $this->success($data);
    }

    public function del()
    {
        $id = input('id/a');//获得ID数组
        $data = $this->store->del($id);
        return $this->success($data);
    }

    public function search()
    {
        $page = input('page');//获得分页
        $str = input('str');//获得搜索的关键词
        $key = input('key', 'id');//获得搜索的列名
        $data = $this->store->select($str, $key, true)->page($page);
        return $this->success($data);
    }


}